/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package controlers;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;
import model.Product;
import model.Store;

/**
 *
 * @author Tasos - O Basket Controler parexei yphresies pou aforoun kyriws to
 * kalathi agorwn. Symphrwnei to Control Level tou BuyProductsScreen afou
 * ekei vriskete to kalathi agorwn
 */
public class BasketControler {
private static EntityManager em3;

    public BasketControler() {
        //Dimiourgia Entity Manager
     EntityManagerFactory emf = Persistence.createEntityManagerFactory("SuperMarketPU");
     em3 = emf.createEntityManager();            
    }

//epistrefei ena proion analoga me to ID toy    
public Product fetchProduct(int id){
//Dimiourgia toy Query
TypedQuery<Product> q1 = em3.createNamedQuery("Product.findByProductId", Product.class);
q1.setParameter("productId", id);
//Apothikeysh toy result
List<Product> productList = q1.getResultList();
//To ID einai monadiko ara tha epistrepsei mia mono eggrafh
Product product = productList.get(0);
//epistrofh toy proiontos
return product;    
}
}
